<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

function Vuser_view()
{
	$str=' (SELECT ';
	$str.=' a.nid 			as nid 			,';
	$str.=' a.ccode 		as ccode 		,';
	$str.=' a.cnote 		as cnote 		,';
	$str.=' a.niduser01 	as niduser01 	,';
	$str.=' a.niduser02 	as niduser02 	,';
	$str.=' a.ddate01 		as ddate01 		,';
	$str.=' a.ddate02 		as ddate02 		,';
	$str.=' a.cuserid 		as cuserid 		,';
	$str.=' a.cpassword 	as cpassword 	,';
	$str.=' a.cemail 		as cemail 		,';
	$str.=' a.cfirstname 	as cfirstname 	,';
	$str.=' a.cmiddlename 	as cmiddlename 	,';
	$str.=' a.clastname 	as clastname 	,';	
	$str.=' concat(a.cfirstname, " " ,  a.cmiddlename, " " , a.clastname)	as cfullname 	,';	
	$str.=' b.cuser_type 	as cisadmin_name,';
	$str.=' a.cisadmin 	as cisadmin 		 ';
	$str.=' FROM ' . Fget_ap_table('tuser') . ' as a , ' . Fget_ap_table('tuser_type') . ' as b';
	$str.=' WHERE a.cdel="0" AND a.cisadmin=b.nid'; 
	$str.=' ) ';
	$str.=' as view ';
	return $str;
}

//
// Danh muc kenh bao cao
//
function Vdepartment_group_view()
{
	$str =' (SELECT ';
	$str.=' a.nid 			as nid 			,';
	$str.=' a.cnote 		as cnote 		,';
	$str.=' a.niduser01 	as niduser01 	,';
	$str.=' a.niduser02 	as niduser02 	,';
	$str.=' a.ddate01 		as ddate01 		,';
	$str.=' a.ddate02 		as ddate02 		,';	
	$str.=' a.ccode			as ccode		,';
	$str.=' a.cgroup		as cgroup		';
	$str.=' FROM ' . Fget_ap_table('tdepartment_group') 	. ' as a ';
	$str.=' WHERE a.cdel="0" '; 
	$str.=' ) ';
	$str.=' as view ';
	
	return $str;
}

//
// huan_lv77
//
function Vdepartment_view()
{
	$str=' (SELECT ';
	$str.=' a.nid 			as nid ,';
	$str.=' a.ccode 		as ccode ,';
	$str.=' a.cdepartment 	as cdepartment ,';
	$str.=' a.nid_index 	as nid_index ,';
	$str.=' a.cindex 		as cindex ,';
	$str.=' a.nid_user 		as nid_user ,';
	$str.=' concat(b.cfirstname, " " ,  b.cmiddlename, " " , b.clastname)	as cfullname 	,';	
	$str.=' a.nid_department_group 	as nid_department_group,';
	$str.=' c.cgroup		as cgroup,';
	
	$str.=' a.cdel 			as cdel ,';
	$str.=' a.cnote 		as cnote ,';
	$str.=' a.cstatus 		as cstatus ,';
	$str.=' a.niduser01 	as niduser01 ,';
	$str.=' a.niduser02 	as niduser02 ,';
	$str.=' a.ddate01 		as ddate01 ,';
	$str.=' a.ddate02 		as ddate02 ';
	
	$str.=' FROM ' . Fget_ap_table('tdepartment')	. ' as a ,';
	$str.='      ' . Fget_ap_table('tuser')    	. ' as b ,';
	$str.='      ' . Fget_ap_table('tdepartment_group') . ' as c ';
	$str.=' WHERE a.cdel="0" '; 
	$str.=' AND   a.nid_user=b.nid'; 
	$str.=' AND   a.nid_department_group=c.nid'; 
	$str.=' ) as view'; 
	
	return $str;
}	
//
// Danh muc kenh bao cao
//

function Vmenu_view() 	
{		
	$str=' ( ';
	$str.=' SELECT ';
	$str.=' a.nid 			as nid 	,';
	$str.=' a.cmenu 		as cmenu 	,';
	$str.=' a.cicon_name 	as cicon_name 	,';	
	$str.=' a.cbasic 		as isbasic 	,';	
	$str.=' a.cindex 		as cindex 	,';	
	$str.=' a.cnode 		as cnode 	,';	
	$str.=' a.cbasic 		as cbasic 	,';	
	$str.=' a.cstatus 		as ccstatus 	';
		
	$str.=' FROM ' ;
	$str.='      ' . Fget_ap_table('tmenu')	. ' as a ';	
	$str.=' WHERE  	a.nid is not null AND a.cdel=0 AND a.cstatus=1';
	$str.=' ) ';
	$str.=' as view ';
	return $str;
}
	
function Vuser_menu_view()
{
	return ' (SELECT * FROM tuser WHERE cdel="0") as vuser ';
}


//
// an_hm87
// DM Tin tuc
function Vnew_view()
{
	$str ='(SELECT';
	$str.=' a.nid				as nid ,';
	$str.=' a.nid_cat_news		as nid_cat ,';
	$str.=' b.ccat_news			as ccat_news ,';
	$str.=' a.ctitle			as ctitle ,';
	$str.=' a.cindex			as cindex ,';
	$str.=' a.ctag				as ctag ,';
	$str.=' a.alwcmt			as alwcmt ,';
	$str.=' a.nstatus 			as nstatus ,';
	$str.=' a.nspecial 			as nspecial ,';
	$str.=' a.niduser01 		as niduser01 ,';
	$str.=' a.nid_section_news	as nid_section_news ,';
	$str.=' c.csection_news		as csection_news ,';	
	$str.=' a.ddate01 			as ddate01 ';

	$str.=' FROM ' . Fget_ap_table('tsection_news') . ' as c	 ,';
	$str.= 		     Fget_ap_table('tnews') . ' as a';
	$str.= ' LEFT JOIN '. Fget_ap_table('tcat_news') . ' as b  ON (a.nid_cat_news = b.nid) ';
	
	$str.=' WHERE 	a.nid is not null ';
	$str.=' AND 	a.nid_section_news 	= c.nid ';
	$str.=' AND  a.nid not in (select f.nid_translate from '.Fget_ap_table2('ttranslate').' as f  where f.cobject_name = "tnews")' ;
	$str.=' ) ';
	$str.=' as view ';
	return $str;
}


function Vbanner_view()
{	
	$str=' (SELECT ';
	$str.=' a.nid					as nid ,';
	$str.=' a.cimage				as cimage,';
	$str.=' a.ctext					as ctext ,';
	$str.=' a.clink					as clink ,';
	$str.=' a.cstatus				as cstatus ,';
	$str.=' concat(b.cfirstname, " " , b.cmiddlename, " " , b.clastname)	as cfullname 	,';	
	$str.=' a.niduser01				as nid_user01 ,';
	$str.=' a.ddate01				as ddate01';
	$str.=' FROM ' . Fget_ap_table('tbanner') .' as a ,';
	$str.=  Fget_ap_table('tuser') .' as b ';
	$str.=' WHERE 	a.niduser01 = b.nid ';
	$str.=' ) ';
	$str.=' as view ';
	return $str;
}


function Vsection_new_view()
{
	$str=' (SELECT ';

	$str.=' a.nid					as nid ,';
	$str.=' a.csection_news			as csection_news,';
	$str.=' a.cnote					as cnote ,';
	$str.=' a.ccode					as ccode ,';
	$str.=' a.ctag					as ctag ,';	
	$str.=' a.nstatus				as nstatus ,';
	$str.=' a.cindex				as cindex ,';
	$str.=' a.niduser01				as nid_user01 ,';
	
	//$str.=' b.nid_org				as nid_org ,';
	//$str.=' b.nid_language			as nid_language,';
	//$str.=' b.nid_translate			as nid_translate,';
	//$str.=' b.ctbl_name				as ctbl_name,';
	
	//$str.=' c.clanguage				as clanguage,';	
	$str.=' a.ddate01				as ddate01';
	$str.=' FROM ' . Fget_ap_table2('tsection_news') . ' as a ' ;
	$str.=') as view ';
	return $str;
}

function Vcat_new_view()
{
	$str=' (SELECT ';

	$str.=' a.nid					as nid ,';
	$str.=' a.ccat_news				as ccat_news,';
	$str.=' a.cnote					as cnote ,';
	$str.=' a.ccode					as ccode ,';
	$str.=' a.ctag					as ctag ,';	
	$str.=' a.nstatus				as nstatus ,';
	$str.=' a.cindex				as cindex ,';
	$str.=' a.niduser01				as nid_user01 ,';
	
	$str.=' a.nid_section_news		as nid_section_news ,';
	$str.=' d.csection_news			as csection_news ,';
	
	//$str.=' b.nid_org				as nid_org ,';
	//$str.=' b.nid_language			as nid_language,';
	//$str.=' b.nid_translate			as nid_translate,';
	//$str.=' b.ctbl_name				as ctbl_name,';
	
	//$str.=' c.clanguage				as clanguage,';
	$str.=' a.ddate01				as ddate01';
	$str.=' FROM ' . Fget_ap_table2('tcat_news') . ' as a ,' ;
	//$str.='      ' . Fget_ap_table2('ttranslate'). ' as b ,';
	//$str.='      ' . Fget_ap_table2('tlanguage') . ' as c, ';
	$str.='      ' . Fget_ap_table2('tsection_news') . ' as d ';
	$str.=' WHERE a.nid 		is not null '; 
	//$str.=' AND   c.nid 		= b.nid_language'; 
	$str.=' AND   d.nid 		= a.nid_section_news'; 
	$str.=' AND  a.nid not in (select f.nid_translate from '.Fget_ap_table2('ttranslate').' as f  where f.cobject_name = "tcat_news")' ;
	$str.=') as view ';
	return $str;
}

function Vsponline_view()
{
	$str=' (SELECT ';
	$str.=' a.nid					as nid ,';
	$str.=' a.ccontact_nick			as ccontact_nick,';
	$str.=' a.cname					as cname,';	
	$str.=' a.cindex				as cindex,';
	$str.=' a.nstatus				as nstatus,';
	$str.=' a.cnote					as cnote,';		
	$str.=' a.niduser01				as niduser01 ,';
	$str.=' a.niduser02				as niduser02 ,';
	$str.=' concat(b.cfirstname, " " , b.cmiddlename, " " , b.clastname)	as cfullname 	,';	
	$str.=' a.ddate01				as ddate01 ,';
	$str.=' a.ddate02				as ddate02 ';
	$str.=' FROM ' . Fget_ap_table('tsponline') . ' as a , ' . Fget_ap_table('tuser') . ' as b';
	$str.=' WHERE a.niduser01=b.nid'; 
	$str.=' ) ';
	$str.=' as view ';
	return $str;
}

function Vemail_manager_view()
{
	$str=' (SELECT ';
	$str.=' a.nid					as nid ,';
	$str.=' a.cemail_manager		as cemail_manager,';
	$str.=' a.cname					as cname,';	
	$str.=' a.cindex				as cindex,';
	$str.=' a.nstatus				as nstatus,';
	$str.=' a.cnote					as cnote,';		
	$str.=' a.niduser01				as niduser01 ,';
	$str.=' a.niduser02				as niduser02 ,';
	$str.=' concat(b.cfirstname, " " , b.cmiddlename, " " , b.clastname)	as cfullname 	,';	
	$str.=' a.ddate01				as ddate01 ,';
	$str.=' a.ddate02				as ddate02 ';
	$str.=' FROM ' . Fget_ap_table('temail_manager') . ' as a , ' . Fget_ap_table('tuser') . ' as b';
	$str.=' WHERE a.niduser01=b.nid'; 
	$str.=' ) ';
	$str.=' as view ';
	return $str;
}

function Vhotline_view()
{
	$str=' (SELECT ';
	$str.=' a.nid						as nid,';	
	$str.=' a.cphone					as cphone,';	
	$str.=' a.cindex					as cindex,';		
	$str.=' a.niduser01				as niduser01 ,';
	$str.=' a.niduser02				as niduser02 ,';
	$str.=' concat(b.cfirstname, " " , b.cmiddlename, " " , b.clastname)	as cfullname 	,';	
	$str.=' a.ddate01				as ddate01 ,';
	$str.=' a.ddate02				as ddate02 ';
	$str.=' FROM ' . Fget_ap_table('tphone') . ' as a , ' . Fget_ap_table('tuser') . ' as b';
	$str.=' WHERE a.niduser01=b.nid'; 
	$str.=' ) ';
	$str.=' as view ';
	return $str;
}

function Vconfig_view()
{
	$str=' (SELECT ';
	$str.=' a.nid					as nid ,';
	$str.=' a.ccode					as ccode,';
	$str.=' a.cvalue				as cvalue,';
	$str.=' a.cname				as cname,';		
	$str.=' a.niduser01				as niduser01 ,';
	$str.=' a.niduser02				as niduser02 ,';
	$str.=' concat(b.cfirstname, " " , b.cmiddlename, " " , b.clastname)	as cfullname 	,';	
	$str.=' a.ddate01				as ddate01 ,';
	$str.=' a.ddate02				as ddate02 ';
	$str.=' FROM ' . Fget_ap_table('tconfig') . ' as a , ' . Fget_ap_table('tuser') . ' as b';
	$str.=' WHERE a.niduser01=b.nid'; 
	$str.=' ) ';
	$str.=' as view ';
	return $str;
}

function Vmodule_view()
{
	$str=' (SELECT ';

	$str.=' a.nid					as nid ,';
	$str.=' a.cmodule				as cmodule,';
	$str.=' a.cnote					as cnote ,';
	$str.=' a.ccode					as ccode ,';
	$str.=' a.ctag					as ctag ,';	
	$str.=' a.nstatus				as nstatus ,';
	$str.=' a.cindex				as cindex ,';
	$str.=' a.niduser01				as nid_user01 ,';
		
	$str.=' a.ddate01				as ddate01';
	$str.=' FROM ' . Fget_ap_table2('tmodule') . ' as a ' ;
	$str.=') as view ';
	return $str;
}


function Vbanner_images_view()
{
	$str=' (SELECT ';

	$str.=' a.nid					as nid ,';
	$str.=' a.cbanner_images		as cbanner_images,';
	$str.=' a.cnote					as cnote ,';
	$str.=' a.ccode					as ccode ,';
	$str.=' a.ctag					as ctag ,';	
	$str.=' a.nstatus				as nstatus ,';
	$str.=' a.cindex				as cindex ,';
	$str.=' a.niduser01				as nid_user01 ,';
	$str.=' a.ddate01				as ddate01';
	$str.=' FROM ' . Fget_ap_table2('tbanner_images') . ' as a ' ;
	$str.=') as view ';
	return $str;
}



function Vsubscribe()
{
	$str=' (SELECT ';
	$str.=' a.nid					as nid ,';
	$str.=' a.ccode					as ccode,';
	$str.=' a.csubscribe			as csubscribe,';
	$str.=' a.cnote					as cnote,';
	$str.=' a.nstatus				as nstatus,';	
	$str.=' a.cindex				as cindex,';
	$str.=' a.niduser01				as niduser01 ,';
	$str.=' a.niduser02				as niduser02 ,';
	$str.=' a.ddate01				as ddate01 ,';
	$str.=' a.ddate02				as ddate02 ';
	
	$str.=' FROM ' . Fget_ap_table('tsubscribe') . ' as a  ';
	$str.=' WHERE a.nid is not null';
	$str.=' ) ';
	$str.=' as view ';
	return $str;
}

function Vconfig()
{
	$str=' (SELECT ';
	$str.=' a.nid					as nid ,';
	$str.=' a.cname					as cname,';
	$str.=' a.cvalue				as cvalue,';
	$str.=' a.cnote					as cnote,';
	$str.=' a.niduser01				as niduser01 ,';
	$str.=' a.niduser02				as niduser02 ,';
	$str.=' a.ddate01				as ddate01 ,';
	$str.=' a.ddate02				as ddate02 ';
	
	$str.=' FROM ' . Fget_ap_table('tconfig') . ' as a  ';
	$str.=' WHERE a.nid is not null';
	$str.=' ) ';
	$str.=' as view ';
	return $str;
}

/// tournament manager module
function Vtournament_view()
{
	$str=' (SELECT ';

	$str.=' a.nid					as nid ,';
	$str.=' a.ctournament			as ctournament,';
	$str.=' a.cnote					as cnote ,';
	$str.=' a.ccode					as ccode ,';
	$str.=' a.nstatus				as nstatus ,';
	$str.=' a.cindex				as cindex ,';
	$str.=' a.niduser01				as nid_user01 ,';
		
	$str.=' a.ddate01				as ddate01';
	$str.=' FROM ' . Fget_ap_table2('ttournament') . ' as a ' ;
	$str.=') as view ';
	return $str;
}

function Vgame_list_view()
{
	$str=' (SELECT ';

	$str.=' a.nid					as nid ,';
	$str.=' a.cgame					as cgame,';
	$str.=' a.ntype					as ntype,';
	$str.=' a.nid_tournament		as nid_tournament,';
	$str.=' b.ctournament			as ctournament,';
	$str.=' a.cimage				as cimage ,';
	$str.=' a.ffee					as ffee ,';
	$str.=' a.cnote					as cnote ,';
	$str.=' a.npermission			as npermission ,';
	$str.=' a.ccode					as ccode ,';	
	$str.=' a.nstatus				as nstatus ,';
	$str.=' a.cindex				as cindex ,';
	$str.=' a.niduser01				as nid_user01 ,';
		
	$str.=' a.ddate01				as ddate01';
	$str.=' FROM ' . Fget_ap_table2('tgame_list') . ' as a ' ;
	$str.=' LEFT JOIN '.Fget_ap_table2('ttournament') .' as b ON(a.nid_tournament = b.nid) ' ;
	$str.=') as view ';
	return $str;
}

function Vgamer_register_view()
{
	$str=' (SELECT ';
	$str.=' a.nid 			as nid 			,';
	$str.=' a.ccode 		as ccode 		,';
	$str.=' a.cnote 		as cnote 		,';
	$str.=' a.cteamname		as cteamname	,';
	$str.=' a.nid_country	as nid_country	,';
	$str.=' b.ccountry		as ccountry		,';
	$str.=' a.niduser01 	as niduser01 	,';
	$str.=' a.niduser02 	as niduser02 	,';
	$str.=' a.ddate01 		as ddate01 		,';
	$str.=' a.ddate02 		as ddate02 		,';
	$str.=' a.cnickname		as cnickname	,';
	$str.=' a.cpassword 	as cpassword 	,';
	$str.=' a.cemail 		as cemail 		,';
	$str.=' a.chandphone	as chandphone	,';
	$str.=' a.cfullname 	as cfullname 	';
	$str.=' FROM ' . Fget_ap_table('tgamer') . ' as a ';
	$str.=' LEFT JOIN ' . Fget_ap_table('tcountry') . ' as b ON a.nid_country = b.nid ';
	
	$str.=' WHERE a.cdel="0" '; 
	$str.=' ) ';
	$str.=' as view ';
	return $str;
}

function Vgamer_game_view()
{	
	$str=' ((SELECT a.nid, b.nid_game_list,  a.cfullname, a.cemail, a.chandphone, a.ccode, a.cteamname, a.cnickname, a.cnote, a.nid_country,a.ddate01, c.ccountry, b.npayment, b.nstatus_payment  , "1" as game_type
FROM  rgn_tuser_single_game as b, rgn_tgamer as a
LEFT JOIN rgn_tcountry as c ON (a.nid_country = c.nid)
WHERE a.nid = b.nid_gamer AND a.cdel= 0 )

UNION

(SELECT a.nid, b.nid_game_list, a.cfullname, a.cemail, a.chandphone, a.ccode, a.cteamname, a.cnickname, a.cnote, a.nid_country,a.ddate01, c.ccountry, b.npayment, b.nstatus_payment  , "2" as game_type
FROM  rgn_tuser_team_game as b, rgn_tgamer as a
LEFT JOIN rgn_tcountry as c ON (a.nid_country = c.nid)
WHERE a.nid = b.nid_gamer AND a.cdel= 0
GROUP BY b.nid_gamer, b.nid_game_list )';
	$str.=' ) ';
	$str.=' as view ';
	return $str;
}

function Vlanguage_view()
{
	$str=' (SELECT ';

	$str.=' a.nid					as nid ,';
	$str.=' a.clanguage				as clanguage,';
	$str.=' a.cnote					as cnote ,';
	$str.=' a.ccode					as ccode ,';
	$str.=' a.ctag					as ctag ,';	
	$str.=' a.nstatus				as nstatus ,';
	$str.=' a.cindex				as cindex ,';
	$str.=' a.niduser01				as nid_user01 ,';
		
	$str.=' a.ddate01				as ddate01';
	$str.=' FROM ' . Fget_ap_table2('tlanguage') . ' as a ' ;
	$str.=') as view ';
	return $str;
}


function Vtran_cat_news($nid_lang = '')
{
	$str=' (SELECT a.nid,  a.ccat_news, tbl_trans.ccat_news as ccat_news_tran, tbl_trans.clanguage, tbl_trans.nid_translate , a.nid_section_news, s.csection_news, a.cindex, tbl_trans.nstatus, a.ddate01, tbl_trans.nid_language
		FROM  '.Fget_ap_table2('tcat_news').' as a
		LEFT JOIN 
		
		(SELECT b.ccat_news, c.nid_original, c.nid_translate, d.clanguage, c.nstatus, c.nid_language
		FROM '.Fget_ap_table2('ttranslate').' as c, '.Fget_ap_table2('tcat_news').' as b, '.Fget_ap_table2('tlanguage').' as d
		WHERE b.nid	= c.nid_translate ';
	
		if($nid_lang != '' || $nid_lang != 0)
			$str.=' AND c.nid_language	= '.$nid_lang ;
		else
		 	$str.=' AND b.nid is null ';
			
	$str.=' AND d.nid	= c.nid_language) as tbl_trans ON (a.nid = tbl_trans.nid_original), '.Fget_ap_table2('tsection_news').' as s 
		
		WHERE a.nid is not null';
		if($nid_lang == '' || $nid_lang == 0)
			$str.=' AND a.nid is null ';
		$str.=' AND a.nid_section_news = s.nid
		AND a.nid not in (select f.nid_translate from '.Fget_ap_table2('ttranslate').' as f  where f.cobject_name = "tcat_news" )';
	$str.=') as view ';
	return $str;
}

function Vtran_news($nid_lang = '')
{
	$str=' (SELECT a.nid,  a.ctitle, a.nid_cat_news, tbl_trans.ctitle as ctitle_tran, tbl_trans.clanguage, tbl_trans.nid_translate , a.nid_section_news, s.csection_news, a.cindex, tbl_trans.nstatus, a.ddate01, tbl_trans.nid_language
		FROM  '.Fget_ap_table2('tnews').' as a
		LEFT JOIN 
		
		(SELECT b.ctitle, c.nid_original, c.nid_translate, d.clanguage, c.nstatus, c.nid_language
		FROM '.Fget_ap_table2('ttranslate').' as c, '.Fget_ap_table2('tnews').' as b, '.Fget_ap_table2('tlanguage').' as d
		WHERE b.nid	= c.nid_translate ';
	
		if($nid_lang != '' || $nid_lang != 0)
			$str.=' AND c.nid_language	= '.$nid_lang ;
		else
		 	$str.=' AND b.nid is null ';
			
	$str.=' AND d.nid	= c.nid_language) as tbl_trans ON (a.nid = tbl_trans.nid_original), '.Fget_ap_table2('tsection_news').' as s 
		
		WHERE a.nid is not null';
		if($nid_lang == '' || $nid_lang == 0)
			$str.=' AND a.nid is null ';
		$str.=' AND a.nid_section_news = s.nid
		AND a.nid not in (select f.nid_translate from '.Fget_ap_table2('ttranslate').' as f  where f.cobject_name = "tnews" )';
	$str.=') as view ';
	return $str;
}


?>